//
//  SecondViewController.m
//  20170207
//
//  Created by xuPeng on 2017/2/7.
//  Copyright © 2017年 陈旭鹏. All rights reserved.
//
#import "Header.h"
#import "MainViewController.h"
#import "FilterSpecilCharViewController.h"
#import "RandomColorViewController.h"
#import "FlashBackViewController.h"
#import "LabelColorViewController.h"
#import "ImageStretchingViewController.h"
#import "DynamicHiddenViewController.h"
#import "FontSpacingViewController.h"
#import "LabelClickViewController.h"
#import "ScratchImageViewController.h"
#import "GifViewController.h"
#import "CAGradientLayerViewController.h"
#import "TintViewController.h"

#import "TableViewAnimationKitHeaders.h"

@interface MainViewController ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic, strong)UITableView *tableView;

@property (nonatomic, strong) NSArray *itemArray;
@property (nonatomic, assign) NSInteger cellNum;
@end

@implementation MainViewController

- (NSArray *)itemArray{

    if (!_itemArray) {
        _itemArray = @[@"过滤特殊字符",@"随机颜色",@"应用直接退出",@"Label字体不同颜色",@"图片拉伸",@"动态隐藏NavigationBar",@"设置字体和行间距",@"Label添加点击事件",@"模仿刮奖界面",@"显示gif图片",@"CAGradientLayer类",@"TintColor"];
    }
    return _itemArray;
}
- (void)viewDidLoad {
    
    [super viewDidLoad];
    self.title = @"常用技巧";
    
    [self performSelector:@selector(loadData) withObject:nil afterDelay:0.5];

    [self.view addSubview:self.tableView];
    
    //设置导航栏透明
//    [[[self.navigationController.navigationBar subviews]objectAtIndex:0] setAlpha:0.1];
    
/*   // 隐藏导航栏下边的黑线
    [self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
    self.navigationController.navigationBar.shadowImage = [[UIImage alloc] init];
 */
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(0, 0, 100, 50);
    [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [btn setTitle:@"Show Again" forState:UIControlStateNormal];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
    [btn addTarget:self action:@selector(loadData) forControlEvents:UIControlEventTouchUpInside];
}

- (void)loadData {
    self.cellNum = self.itemArray.count;
    [self.tableView reloadData];
    [self starAnimationWithTableView:self.tableView];
    
}
- (void)viewWillDisappear:(BOOL)animated{
    
    [super viewWillDisappear:YES];

}
//- (void)initTableView{
//    
//    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, PW, PH) style:UITableViewStylePlain];
//    UIView *view = [UIView new];
//    view.backgroundColor = [UIColor clearColor];
//    [_tableView setTableFooterView:view];
//    
//    if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
//        
//        // UIEdgeInsets 的四个参数分别是相对于cell的上、左、下、右的距离，都是CGFloat型。
//        // 但是这个方法中貌似只有左和右能用
//        [self.tableView setSeparatorInset:UIEdgeInsetsMake(0, 0, 0, 0)];
//    }
//    
//    [_tableView setSeparatorColor:[UIColor cyanColor]];
//    
//    [self.view addSubview:self.tableView];
//}
#pragma mark - Getter
-(UITableView *)tableView {
    if (!_tableView) {
            self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, PW, PH) style:UITableViewStylePlain];
            UIView *view = [UIView new];
            view.backgroundColor = [UIColor clearColor];
            [_tableView setTableFooterView:view];
        
            self.tableView.delegate = self;
            self.tableView.dataSource = self;
            if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
        
                // UIEdgeInsets 的四个参数分别是相对于cell的上、左、下、右的距离，都是CGFloat型。
                // 但是这个方法中貌似只有左和右能用
                [self.tableView setSeparatorInset:UIEdgeInsetsMake(0, 0, 0, 0)];
            }
        
            [_tableView setSeparatorColor:[UIColor cyanColor]];
    }
    return _tableView;
}
#pragma mark - 黄金三问
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.cellNum;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *textcellName = @"cell";
    UITableViewCell *textCell = [tableView dequeueReusableCellWithIdentifier:textcellName];
    if (!textCell) {
        textCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:textcellName];
    }
    
    textCell.textLabel.text = self.itemArray[indexPath.row];
    return textCell;
    
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0) {
        
        FilterSpecilCharViewController *FVC = [[FilterSpecilCharViewController alloc] init];
        [self.navigationController pushViewController:FVC animated:NO];
        
    }else if (indexPath.row == 1){
        RandomColorViewController *RVC = [[RandomColorViewController alloc] init];
        [self.navigationController pushViewController:RVC animated:NO];
        
    }else if (indexPath.row == 2){
        FlashBackViewController *FVC = [[FlashBackViewController alloc] init];
        [self.navigationController pushViewController:FVC animated:NO];
        
    }else if (indexPath.row == 3){
        LabelColorViewController *LVC = [[LabelColorViewController alloc] init];
        [self.navigationController pushViewController:LVC animated:NO];
        
    }else if (indexPath.row == 4){
        ImageStretchingViewController *IVC = [[ImageStretchingViewController alloc] init];
        [self.navigationController pushViewController:IVC animated:NO];
        
    }else if (indexPath.row == 5){
        DynamicHiddenViewController *DVC = [[DynamicHiddenViewController alloc] init];
        [self.navigationController pushViewController:DVC animated:NO];
        
    }else if (indexPath.row == 6){
        FontSpacingViewController *FVC = [[FontSpacingViewController alloc] init];
        [self.navigationController pushViewController:FVC animated:NO];
        
    }else if (indexPath.row == 7){
        LabelClickViewController *LVC = [[LabelClickViewController alloc] init];
        [self.navigationController pushViewController:LVC animated:NO];
    }else if (indexPath.row == 8){
        ScratchImageViewController *SVC = [[ScratchImageViewController alloc] init];
        [self.navigationController pushViewController:SVC animated:NO];
    }else if (indexPath.row == 9){
        GifViewController *GVC = [[GifViewController alloc] init];
        [self.navigationController pushViewController:GVC animated:NO];
    }else if (indexPath.row == 10){
        CAGradientLayerViewController *CVC = [[CAGradientLayerViewController alloc] init];
        self.hidesBottomBarWhenPushed = YES; // 隐藏tabBar
        [self.navigationController pushViewController:CVC animated:NO];
    }
    else if (indexPath.row == 11){
        TintViewController *TVC = [[TintViewController alloc] init];
        self.hidesBottomBarWhenPushed = YES; // 隐藏tabBar
        [self.navigationController pushViewController:TVC animated:NO];
    }
}
- (void)starAnimationWithTableView:(UITableView *)tableView {
    
    int i = (arc4random()%10)+1;
    [TableViewAnimationKit showWithAnimationType:i tableView:tableView];
}

@end
